
void OneKeyCloseWidget::keyPressEvent(QKeyEvent *keyEvent)
{
    if (this->focusWidget() != m_tableView) {
        return QWidget::keyPressEvent(keyEvent);
    }

    if (keyEvent->matches(QKeySequence::Copy)) {
        QString copiedText;
        QModelIndexList selectList = m_tableView->selectionModel()->selectedIndexes();
        if (selectList.count() <= 0)
            return;

        int currentRow = selectList.at(0).row();
        for (int i = 0; i < selectList.count(); i++) {
            if (currentRow != selectList.at(i).row()) {
                currentRow = selectList.at(i).row();
                copiedText.append("\n");
                copiedText.append(selectList.at(i).data().toString());
                continue;
            }
            if (i != 0) {
                copiedText.append("\t");
            }
            copiedText.append(selectList.at(i).data().toString());
        }
        copiedText.append("\n");
        QApplication::clipboard()->setText(copiedText);
        keyEvent->accept();
    }
    else if (keyEvent->matches(QKeySequence::Paste)) {
        QString onPasteText = QApplication::clipboard()->text();
        QStringList datasByRow = onPasteText.split("\n", QString::SkipEmptyParts);
        QModelIndexList selectList = m_tableView->selectionModel()->selectedIndexes();
        QModelIndex current_index = selectList.at(0);
        QModelIndex last_index = selectList.last();
        //剪切板中的文本的行数不能大于当前行开始到结尾的行数
        for (int i = 0; i <= last_index.row() - current_index.row(); ++i) {
            if (datasByRow.count() <= i)
                datasByRow.append(datasByRow);
            QStringList datasPerRow = datasByRow.at(i).split("\t");
            for (int k = 0; k <= last_index.column() - current_index.column(); ++k) {
                if (datasPerRow.count() <= k)
                    datasPerRow.append(datasPerRow);
                m_sqlModel->setData(m_sqlModel->index(i + current_index.row(), k + current_index.column()), datasPerRow.at(k));
            }
        }
        keyEvent->accept();
        update();
    }
}